package run;

import processing.core.PApplet;
import processing.core.PVector;

public class RepulseRule implements DistRule {
	public void execRule(LineCell a, LineCell b, Env e, PApplet p) {
		
		if (a != b) {
			PVector diff = PVector.sub(a.loc, b.loc);
			
			diff.normalize();
			
			PVector rep = new PVector(1, 1, 1);
			
			float dist = a.loc.dist(b.loc);
			
			//TODO prohibit this kind of direct adding; we want
			// smoother curves; allow only to dictate it managed by
			// a MAX Turn Rate (x radians per step)
			
			if (dist > 0) {
				rep.div(dist);
				rep.mult(3F);
				rep.mult(diff);
				a.dir.add(rep);
			}
		}
	}
}
